<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.sinodata.bsm.common.vo.Probe"%>
<%@ include file="../include/taglib.jsp"%>
<%
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragrma", "no-cache");
    response.setDateHeader("Expires", 0);
    Long probeId = Long.parseLong(request.getParameter("id"));
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>probe诊断页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/table.jsp"%>
	
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/style/default/bsm/sub_menu.css" />
	
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/style/default/bsm/sub_menu.css" />

<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/style/default/bsm/selfmainten/probe.css" />
	
<script type=text/javascript>

	function timeMinMin(day1, day2){
	    var y1, y2, y3, m1, m2, m3, d1, d2, d3, h1, h2, h3, _m1, _m2, _m3, s1, s2, s3;
	    var reg = /-|\/|:| /;
	    //dayinfo -  用正则分割
	    var DI1 = day1.split(reg);
	    var DI2 = day2.split(reg);
	    var date1 = new Date(DI1[0], DI1[1], DI1[2], DI1[3], DI1[4], DI1[5]);
	    var date2 = new Date(DI2[0], DI2[1], DI2[2], DI2[3], DI2[4], DI2[5]);
	    //用距标准时间差来获取相距时间
	    var minsec = Date.parse(date1) - Date.parse(date2);
	    var mins = (minsec<0?-minsec:minsec) / 1000 / 60 ; //factor: second / minute / hour / day
	   
	    return mins;
	}
	
	
	
	function compareTime(){
		$.ajax({
			url : 'probe!getTimeVal.action', 
			type : 'POST',
			dataType : "json",
			data : {
				id:<%=probeId%>
			},
			success : function(data) {
				$('#bsmTime').text(data.bsm);
				$('#probeTime').text(data.probe);
				if(data.bsm == data.probe){
					$('#probeTime').next().append('<span><p><h3><font color=#0000ff>时间相同</font></h3></p></span>');
				}else if(timeMinMin(data.bsm,data.probe)<5){
					$('#probeTime').next().append('<span><p><h3><font color=#0000ff>时间差值在可容忍范围内</font></h3></p></span>');
				}else{
					$('#probeTime').next().append('<span><p><h3><font color=#ff0000>时间差值较大 建议修改系统时间  并重启应用</font></h3></p></span>');
				}
			}
		});
	}
	
	
	
	
	function compareResCnt(){
		$.ajax({
			url : 'probe!getResCnt.action', 
			type : 'POST',
			dataType : "json",
			data : {
				id:<%=probeId%>
			},
			success : function(data) {
				$('#bsmResC').text(data.bsm);
				$('#probeResC').text(data.probe);
				$('#probeNormal').text(data.probenormal);
				$('#probePaused').text(data.probepaused);
				
				if(data.bsm <5000){
					$('#bsmResC').next().append('<span><p><h3><font color=#0000ff>资源数目合适</font></h3></p></span>');
				}else{
					$('#bsmResC').next().append('<span><p><h3><font color=#ff0000>资源数目过多</font></h3></p></ span>');
				}
				
				if(data.bsm == data.probe){
					$('#probeResC').next().append('<span><p><h3><font color=#0000ff>与应有资源数相同</font></h3></p></span>');
				}else{
					//$('#probeResC').next().append('<span><p><h3><font color=#ff0000>资源数目不同  建议  <a href="javascript:restart();">重启</a> 此Probe</font></h3></p></ span>');
					$('#probeResC').next().append('<span><p><h3><font color=#ff0000>资源数目不同  建议  重启此Probe</font></h3></p></ span>');
				}
			}
		});
	}
	
	function listJobDetail(){
		$('#probedetail').css('display','');
		
	}
	
	var timeout = 20;
	function timer(){
        $('#timeCount').css('font','#ff0000').text(timeout);
        timeout--;
        if (timeout == 0) {
        	location.reload();
        }
        else {
            setTimeout("timer()", 1000);
        }
	}
	
	//重启probe
	function restart(probeId){
		$('#startTip').css('display','');
		timer();
		$.ajax({
			url : 'probe!restartProbe.action', // 
			type : 'POST',
			dataType : "json",
			data : {
				id:<%=probeId%>
			},
			success : function(data) {
				
			}
		});
		
	}
	
	
	function getProbeTask(){
		$.ajax({
			url : 'probe!getProbeTask.action', 
			type : 'POST',
			dataType : "json",
			data : {
				id:<%=probeId%>
			},
			success : function(data) {
				
				$('#probeTaskC').text(data.total);
				$('#probeRealTaskC').text(data.real);
				$('#probeRunningTaskC').text(data.run);
				//if((data.total - data.run)>50){
				if(data.run/data.total<0.9){
					$('#probeTaskC').next().append('<span><p><h3><font color=#0000ff>正在运行任务数适中</font></h3></p></span>');
				}else{
					$('#probeTaskC').next().append('<span><p><h3><font color=#ff0000>空闲任务数较小 建议增大Quartz线程配置</font></h3></p></span>');
				}
				
				$('#probeRealTaskC').next().append('<span><p><h3><font color=#777777>[此值应略大于Probe正常监控的资源数]</font></h3></p></span>');
				
				if(data.run>0){
					$('#probeRunningTaskC').next().append('<span ><a  href="javascript:listJobDetail();"><p><h3><font color=#555555>查看详细列表</font></h3></p></a></span>');
				}
				
				var oTable=	$('#probelist').dataTable({
		    		"aaData":data.detail,
		    		"bPaginate": false,
		    		"bSort": true,
					"bFilter":false,
					"bJQueryUI":false,
					"sPaginationType": "full_numbers",
					"aoColumns":[
						{"mDataProp":"resid"},
						{"mDataProp":"collect","bSortable": false},
						{"mDataProp":"begin","bSortable": true},
						{"mDataProp":"time","bSortable": true}
					],
					"oLanguage": {
						"sInfo": "", 
					}
			   });
			}
		});
	}
	
	function getProbeJVM(){
		$.ajax({
			url : 'probe!getProbeJVM.action', 
			type : 'POST',
			dataType : "json",
			data : {
				id:<%=probeId%>
			},
			success : function(data) {
				//$('#singleTime').text(data.time);
				
				$('#trap').text(data.trap);
				$('#jdkver').text(data.jdkver);
				$('#jvmProvider').text(data.jvmProvider);
				$('#jvmMax').text(data.max);
				$('#jvmTotal').text(data.total);
				$('#jvmFree').text(data.free);
				$('#jvmUae').text(data.usable);
				
				if(data.trap =='NO'){
					$('#trap').next().append('<span><p><h3><font color=#ff0000>服务未启动</font></h3></p></span>');
				}else{
					$('#trap').next().append('<span><p><h3><font color=#0000ff>服务已启动</font></h3></p></span>');
				}
				
				if(data.usable/data.max>0.1){
					$('#jvmUae').next().append('<span><p><h3><font color=#0000ff>有足够可用内存</font></h3></p></span>');
				}else{
					$('#jvmUae').next().append('<span><p><h3><font color=#ff0000>可用内存较小 建议增大内存配置</font></h3></p></span>');
				}
				
				if(/^1.6.*/.exec(data.jdkver)!=null){
					$('#jdkver').next().append('<p><h3><font color=#0000ff>JDK版本合适</font></h3></p>');
				}else{
					if((/^1.5\.*/.exec(data.jdkver)!=null) || (/^1.4\.*/.exec(data.jdkver)!=null)){
						$('#jdkver').next().append('<p><h3><font color=#ff0000>JDK版本太小</font></h3></p>');
					}else{
						$('#jdkver').next().append('<p><h3><font color=#ff0000>JDK版本不合适</font></h3></p>');
					}
				}
				
			}
		});
	}
	
	function back(){
		var backUrl = document.referrer;
		location.assign(backUrl);
	}
	
	function refresh(){
		//compareTime();
		//compareResCnt();
		//getProbeJVM();
		//getProbeTask();
		//$('#probedetail').css('display','none');
		location.reload();
	}

	
    $(function() {
    	compareTime();
    	compareResCnt();
    	getProbeJVM();
    	getProbeTask();
    });

</script>

</head>
<body>
	<div class="top" id="top" >
				<ul >
				      <li  class="top-li"><span >采集器ID：</span>
				          <span id="probeid"  >${probe.id}</span>
				      </li>
				      <li class="top-li">
				          <span >采集器名称：</span>
				          <span id="probeid"  >${probe.name}</span>
					  </li>
					  <!--  
				      <li  class="top-li "><span ><font color=#0000ff>正在重启</font></span>
				          &nbsp;
				          <span  id="timeCount" style="color:#ff0000;font-weight: bold;"></span>
				          <span ><font color=#0000ff>S后页面自动刷新...</font></span>
					  </li>
					 -->
				      <li class="li-a-btn"><a id="return" name="common" href="javascript:back();"
							class="perf"> 返回 </a>
					  </li>
					  <li class="li-a-btn">|</li>
					  <li class="li-a-btn"><a id="return" name="common" href="javascript:refresh();"
							class="perf"> 手动刷新 </a>
				      </li>
				</ul>
	</div>

	<div style="width:80%;float:left;">
		<fieldset class="column b-1">
			<legend> 时间分析 </legend>
			<div class="col-net-main">
				<div style="float:left;width:98%;height:auto;">
					<ul class="col-l-ul">
					      <li><span class="col-l-ul-l" >监控中心主机当前时间：</span><span
								id="bsmTime" class="col-l-ul-mid" ></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >Probe所在主机当前时间:：</span><span
								id="probeTime" class="col-l-ul-mid"  ></span>
								<span class="col-l-ul-right"></span>
						  </li>
					</ul>
				</div>
			</div>
		</fieldset>
		<fieldset class="column b-1">
			<legend> 资源分析 </legend>
			<div class="col-net-main" style="height:auto;">
				<div style="float:left;width:98%;">
					<ul class="col-l-ul">
					      <li><span class="col-l-ul-l" >此Probe应有的资源总数：</span><span
								id="bsmResC" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe实际拥有的资源总数：</span><span
								id="probeResC" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe正常监控的资源数：</span><span
								id="probeNormal" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe暂停监控的资源数：</span><span
								id="probePaused" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					</ul>
				</div>
			</div>
		</fieldset>
		
		<fieldset class="column b-1">
			<legend> 综合分析 </legend>
			<div class="col-net-main" style="height:auto;">
				<div style="float:left;width:98%">
					<ul class="col-l-ul">
					<!--  
					      <li><span class="col-l-ul-l" >BSM与此Probe单次同步通信用时(Sec)：</span><span
								id="singleTime" class="col-l-ul-mid" ></span>
								<span class="col-l-ul-right"></span>
					
						  </li>
			         -->
			              <li><span class="col-l-ul-l" >TRAP接收服务启动状态：</span><span
								id="trap" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe的JDK运行时环境版本：</span><span
								id="jdkver" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe的JDK运行时环境供应商：</span><span
								id="jvmProvider" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe的JVM最大内存约(MB)：</span><span
								id="jvmMax" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe的JVM已分配内存约(MB)：</span><span
								id="jvmTotal" class="col-l-ul-mid" ></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe的JVM已分配内存中的剩余空间约(MB)：</span><span
								id="jvmFree"class="col-l-ul-mid" ></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe的JVM最大可用内存约(MB)：</span><span
								id="jvmUae" class="col-l-ul-mid" ></span>
								<span class="col-l-ul-right"></span>
						  </li>
					</ul>
				</div>
			</div>
		</fieldset>
		
		<fieldset class="column b-1" >
			<legend> 任务分析 </legend>
			<div class="col-net-main" style="height:auto;">
				<div style="float:left;width:98%">
					<ul class="col-l-ul">
					      <li><span class="col-l-ul-l" >此Probe允许的同时执行的最大任务数：</span><span
								id="probeTaskC" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe的任务总数：</span><span
								id="probeRealTaskC" class="col-l-ul-mid"></span>
								<span class="col-l-ul-right"></span>
						  </li>
					      <li><span class="col-l-ul-l" >此Probe正在执行的任务数：</span><span
								id="probeRunningTaskC" class="col-l-ul-mid" ></span>
								<span class="col-l-ul-right"></span>
						  </li>
					</ul>
				</div>
			</div>
		</fieldset>
		
		<fieldset id="probedetail" class="column b-1" style="display:none;" >
		    <legend> 任务列表 </legend>
			<table id="probelist" name="probelist" width="100%" cellpadding="0" cellspacing="0" border="0" class="display" >
				<thead>
					<tr>
						<th width="4%">资源ID</th>
						<th width="4%">采集任务ID</th>
						<th width="3%">开始时间</th>
						<th width="5%">运行时长(Sec)</th>
					</tr>
				</thead>
			</table>
		</fieldset>
   </div>
</body>
</html>